package com.neusoft.neuiotms.dcom.model.hn;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "neuiot_inspection_plan_hn")
@org.hibernate.annotations.Table(appliesTo = "neuiot_inspection_plan_hn", comment = "海南日巡检计划表")
public class HnInspectionPlan extends AbstractAuditModel {

    private static final long serialVersionUID = -716667364281132683L;

    @NotBlank(message = "编码")
    @Length(max = 64, message = "编码不能超过{max}位")
    @Column(length = 64, nullable = false)
    @Comment("varchar(64) NOT NULL COMMENT '编码'")
    private String code;

    @Column(nullable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NULL DEFAULT NULL COMMENT '开始时间'")
    private Date startDateTime;

    @Column(nullable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NULL DEFAULT NULL COMMENT '结束时间'")
    private Date endDateTime;

    //    @OneToMany
    //    private List<HnInspectionPlanInstitution> institution = new ArrayList<>();

    @NotBlank(message = "厅局编码")
    @Length(max = 255, message = "厅局编码不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '厅局编码'")
    private String institutionCode;

    @NotBlank(message = "厅局名称")
    @Length(max = 255, message = "厅局名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '厅局名称'")
    private String institutionName;

    @NotBlank(message = "创建人编码")
    @Length(max = 255, message = "创建人编码不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '创建人编码'")
    private String userCode;

    @Length(max = 255, message = "创建人名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '创建人名称'")
    private String userName;

    @Length(max = 32, message = "cron表达式不能超过{max}位")
    @Column(length = 32, nullable = false)
    @Comment("varchar(32) NOT NULL COMMENT 'cron表达式'")
    private String cronTime;

    @Column(length = 32, nullable = false)
    @Comment("varchar(32) NOT NULL COMMENT '持续时长'")
    private Integer duration;

    /** 计划状态 **/
    private boolean disabled;

    /** 删除标识 **/
    private boolean delFlag;

    /** 版本号 **/
    private int version;

    /** 维护关系方 */
    @ManyToMany(targetEntity = HnInspectionItem.class)
    @JoinTable(name = "neuiot_ref_inspetion_plan_item_hn")
    @LazyCollection(LazyCollectionOption.FALSE)
    List<HnInspectionItem> items = new ArrayList<>();

    @OneToMany(mappedBy = "hnInspectionPlan")
    private List<HnInspectionTask> task = new ArrayList<>();

}
